﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using System.Data;

namespace HY.WEB.SYS
{
    public partial class user_role_add : PageBase
    {
        public string us;
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request["stype"]))
                {
                     hidstype.Text = Request["sid"].Trim();                
                }
                fill();
            }       
        }

        void fill()
        {
            //用户
            DataTable e = BLL.Bllbase.get_table("[sys_user]");
            ddlperson.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlperson.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["user_name"].ToString().Trim(), e.Rows[i]["sbh"].ToString().Trim()));
            }
            ddlperson.DataBind();

            //角色
             e = BLL.Bllbase.get_table("[menu_safe]");
            ddlmenu.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlmenu.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["bname"].ToString().Trim(), e.Rows[i]["sid"].ToString().Trim()));
            }
            ddlmenu.DataBind();

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string ubh = ddlperson.SelectedValue;
            string uname = ddlperson.SelectedText;
            string mm = ddlmenu.SelectedText;
            string menu = ddlmenu.SelectedValue;

            DAL.DbHelperSQL.ExecuteNonQuery("insert into user_safe(ubh,uname,mname,menu)"+
                " values('" + ubh + "','" + uname + "','" + mm + "','" + menu + "')");

            Alert.Show("添加完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());       
        }

       
    }
}